export enum ResponseCode {
  Success = 1,
  Fail = 0,
}

interface Body<T> {
  data?: T;
  message?: string;
  code?: ResponseCode;
}

export class ResponseBody<T = null> implements Body<T> {
  data?: T;
  message?: string;
  code?: ResponseCode;
  constructor(params: string);
  constructor(params: Body<T>);
  constructor(params: any) {
    if (typeof params === 'string') {
      this.message = params;
      this.code = ResponseCode.Success;
      this.data = null;
      return;
    }
    const { data, message, code } = params as Body<T>;
    this.code = code !== undefined ? code : ResponseCode.Success;
    this.message = message !== undefined ? message : '';
    this.data = data || null;
  }
}
